package com.util.thread;

import javax.xml.bind.SchemaOutputResolver;
import java.util.concurrent.*;

/**
 * @author xin.ding
 * @date 2020/10/31 16:34
 */
public class SubThreadException {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(8);
        Future future = executorService.submit(new ChildThread());
        try {
            Object o = future.get();
            System.out.println(o);
        } catch (InterruptedException e) {
            System.out.println(String.format("handle exception in child thread. %s", e));
        } catch (ExecutionException e) {
            System.out.println(String.format("handle exception in child thread. %s", e));
        } finally {
            if (executorService != null) {
                executorService.shutdown();
            }
        }
    }

    static class ChildThread implements Callable<Boolean> {
        @Override
        public Boolean call() throws Exception {
            System.out.println("do something 1");
//            exceptionMethod();
            System.out.println("do something 2");
            return true;
        }

        private void exceptionMethod() {
            throw new RuntimeException("ChildThread1 exception");
        }
    }
}
